package com.jushu.storbox.actions;

import android.content.Context;
import android.os.Handler;

import com.jushu.storbox.entities.FileFolderInfo;
import com.jushu.storbox.entities.FileType;
import com.jushu.storbox.util.LogUtil;
import com.huawei.sharedrive.sdk.android.exception.ClientException;

public class DownloadAction extends BaseAction {

    protected static final String TAG = DownloadAction.class.getSimpleName();

    public void downloadFolder(Context context, final FileFolderInfo folderInfo, final boolean syncStatus, Handler messageHandler) {
        if (folderInfo.getType() != FileType.Folder.value()) {
            LogUtil.e(TAG, "the download item is not a folder!");
            return;
        }
        executeRunTask(new RealTaskRunnable(context, messageHandler) {
            protected void doTask(Context context, Handler msgHandler) throws ClientException {
                new DownloadEntity(context, msgHandler, folderInfo, syncStatus).startDownloadFolder();
            }
        });
    }

    public void downloadFile(Context context, final FileFolderInfo folderInfo, final boolean syncStatus, Handler messageHandler) {
        if (folderInfo.getType() != FileType.File.value()) {
            LogUtil.e(TAG, "the download item is not a file!");
            return;
        }
        executeRunTask(new RealTaskRunnable(context, messageHandler) {
            protected void doTask(Context context, Handler msgHandler) throws ClientException {
                new DownloadEntity(context, msgHandler, folderInfo, syncStatus).startDownloadFile();
            }
        });
    }

}
